home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
tplib21.zip
/
INSTALL.EXE
/
HELPCONV.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-24
|
5KB
|
170 lines
(*
TURBO PASCAL LIBRARY 2.1
HELPCONV: File conversion utility for help system.
*)
PROGRAM HELPCONV(InFile,OutFile,Output);
{$V-}
USES
DOS,STDERR,CRTCLERR,STRINGS;
TYPE
HelpIndexString = STRING[30]; { String to hold help index }
HelpRec = RECORD { Record format in help file }
SecNum: BYTE;
CASE INTEGER OF
0: (SecOfs: LONGINT;
SecLength: WORD;
SecName: HelpIndexString);
1: (HelpText: STRING[80]);
END;
CONST
SectionDelim = '#';
NumberDelim = ':';
VAR
InFile: TEXT; { Input text file }
OutFile: FILE OF HelpRec; { Output file }
HelpVar: HelpRec;
IndexSize: BYTE; { Number of sections }
HelpIndexStr: ARRAY[1..255] OF HelpIndexString; { Index phrases }
HelpSecOfs: ARRAY[1..255] OF LONGINT; { Offset to sections }
HelpSecLength: ARRAY[1..255] OF WORD; { Length sections }
s: STRING;
d: DirStr;
e: ExtStr;
i,j: BYTE;
LineCount: LONGINT;
x: INTEGER;
PROCEDURE FormatError;
VAR
s: STRING[20];
BEGIN
STR(LineCount,s);
WriteStdErr(CONCAT('ERROR: Input-file format error at line ',s));
CLOSE(InFile);
CLOSE(OutFile);
HALT(1);
END;
PROCEDURE ReadNextLine;
BEGIN
IF EOF(InFile) THEN
BEGIN
WriteStdErr('ERROR: Unexpected end of input file');
CLOSE(InFile);
CLOSE(OutFile);
HALT(1);
END;
READLN(InFile,s);
END;
BEGIN
WRITELN('HELPCONV version 2.1 - File conversion utility for help system.');
WRITELN('Copyright (C) 1991, 1993 Paul Coxwell. ',
'All rights reserved.', #10);
IF ParamCount=0 THEN
BEGIN
WRITELN('Command syntax:',#10);
WRITELN(' HELPCONV input-file [output-file]',#10);
WRITELN('Default output-file is same path and name as input,',
' but with "HLP" extension.',#10);
EXIT;
END;
ASSIGN(InFile,ParamStr(1));
{$I-}
RESET(InFile); { Open input file }
{$I+}
IF IOResult<>0 THEN
BEGIN
WriteStdErr('ERROR: Cannot open input file');
HALT(1);
END;
FSplit(ParamStr(1),d,s,e);
s:=FileSpecDefault(ParamStr(2),d,s,'.HLP');
ASSIGN(OutFile,s);
{$I-}
REWRITE(OutFile); { Open output file }
{$I+}
IF IOResult<>0 THEN
BEGIN
WriteStdErr(CONCAT('ERROR: Cannot open output file ',s));
CLOSE(InFile);
HALT(1);
END;
WriteLn('Creating help file ',s);
WriteLn;
ReadNextLine; { Get number of sections }
LineCount:=1;
VAL(s,IndexSize,x);
IF (x<>0) OR (IndexSize<1) THEN
FormatError;
WITH HelpVar DO
BEGIN
SecNum:=0;
SecOfs:=-1;
SecLength:=0;
SecName:='';
END;
FOR i:=1 TO IndexSize DO { Clear array variables, write empty }
WRITE(OutFile,HelpVar); { index records to file }
REPEAT
ReadNextLine;
INC(LineCount);
UNTIL (LENGTH(s)>0) AND (s[1]=SectionDelim);
FOR i:=1 TO IndexSize DO { Read & convert each section's text }
BEGIN
VAL(Precede(Follow(s,SectionDelim),NumberDelim),j,x);
IF (x<>0) OR (j<>i) THEN
FormatError;
HelpSecOfs[i]:=FilePos(OutFile);
HelpIndexStr[i]:=Follow(s,NumberDelim);
HelpSecLength[i]:=0;
REPEAT
ReadNextLine;
INC(LineCount);
IF (LENGTH(s)=0) OR (s[1]<>SectionDelim) THEN
BEGIN
WITH HelpVar DO
BEGIN
SecNum:=i;
HelpText:=s;
END;
WRITE(OutFile,HelpVar);
INC(HelpSecLength[i]);
IF HelpSecLength[i]>1000 THEN
FormatError;
END;
UNTIL (LENGTH(s)>0) AND (s[1]=SectionDelim);
END;
SEEK(OutFile,0);
FOR i:=1 TO IndexSize DO { Build index in file }
BEGIN
WITH HelpVar DO
BEGIN
SecNum:=0;
SecOfs:=HelpSecOfs[i];
SecLength:=HelpSecLength[i];
SecName:=HelpIndexStr[i];
END;
WRITE(OutFile,HelpVar);
END;
CLOSE(InFile);
CLOSE(OutFile);
WRITELN('Conversion successful');
WRITELN(LineCount,' lines processed, ',IndexSize,' sections.');
END.